<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/reset.css">
    <style>
        td {
            border: 0.5px solid #333;
            padding: 0 20px;
        }

        table {
            line-height: 45px;
            border-spacing: 0;
            border-collapse: collapse;
        }
    </style>
</head>

<body>
    <table>
        <!-- <tr>
            <td>1x1=01</td>
        </tr>
        <tr>
            <td>1x1=01</td>
            <td>2x2=02</td>
        </tr>
        <tr>
            <td>1x1=01</td>
            <td>2x2=02</td>
            <td>3x3=03</td>
        </tr>
        <tr>
            <td>1x1=01</td>
            <td>2x2=02</td>
            <td>3x3=03</td>
            <td>4x4=04</td>
        </tr>
        <tr>
            <td>1x1=01</td>
            <td>2x2=02</td>
            <td>3x3=03</td>
            <td>4x4=04</td>
            <td>5x5=05</td>
        </tr>
        <tr>
            <td>1x1=01</td>
            <td>2x2=02</td>
            <td>3x3=03</td>
            <td>4x4=04</td>
            <td>5x5=05</td>
            <td>6x6=06</td>
        </tr>
        <tr>
            <td>1x1=01</td>
            <td>2x2=02</td>
            <td>3x3=03</td>
            <td>4x4=04</td>
            <td>5x5=05</td>
            <td>6x6=06</td>
            <td>7x7=07</td>

        </tr>
        <tr>
            <td>1x1=01</td>
            <td>2x2=02</td>
            <td>3x3=03</td>
            <td>4x4=04</td>
            <td>5x5=05</td>
            <td>6x6=06</td>
            <td>7x7=07</td>
            <td>8x8=08</td>
        </tr>
        <tr>
            <td>1x1=01</td>
            <td>2x2=02</td>
            <td>3x3=03</td>
            <td>4x4=04</td>
            <td>5x5=05</td>
            <td>6x6=06</td>
            <td>7x7=07</td>
            <td>8x8=08</td>
            <td>9x9=09</td>
        </tr> -->
    </table>
</body>
<script>
    // 1. 动态生成之前先写静态的
    // 2. 动态生成

    // var html = "";

    // for(){
    //     for(){
    //         html += ``
    //     }
    // }

    // table.innerHTML = html;

    // 外层循环  循环的总层数.
    // for (var i = 1; i <= 9; i++) {
    //     document.write(i + ":")
    //     // 内层循环 控制每层打印的内容
    //     for (var j = 1; j <= i; j++) {
    //         document.write(j + " ");
    //     }
    //     document.write("<br>");
    // }


    // document.write("<table>");

    // for (var i = 1; i <= 9; i++) {
    //     document.write("<tr>")
    //     // 内层循环 控制每层打印的内容
    //     for (var j = 1; j <= i; j++) {
    //         document.write("<td>" + j + "x" + i + "=" + j * i + "</td>");
    //     }
    //     document.write("</tr>");
    // }

    // document.write("</table>");


    var html = ""; // 全局变量 存储table中的html结构
    for (var i = 1; i <= 9; i++) {
        html += "<tr>";
        // 内层循环 控制每层打印的内容 
        for (var j = 1; j <= i; j++) {
            // html += "<td>" + (j + "x" + i + "=" + j * i) + "</td>";
            html += `<td>${j}x${i}=${j * i}</td>`;
        }
        html += "</tr>";
    }
    console.log(html);

    var table = document.getElementsByTagName("table")[0];

    table.innerHTML = html;



</script>

</html>